<?php
include_once("config.php");

function func_bw_volume_domain_top10_periode($Start, $End){
	// Connect to server and select databse.
    global $host, $username, $password, $db_name;

	mysql_connect("$host", "$username", "$password")or die("cannot connect");
	mysql_select_db("$db_name")or die("cannot select DB");

	$sql="select domein, sum(size) as size from logbook where Timestamp >= '$Start' and Timestamp <= '$End' group by domein limit 0, 10;";
    $result=mysql_query($sql);

    $bw = array(
            array('',0), array('',0), array('',0), array('',0),
            array('',0), array('',0), array('',0), array('',0),
            array('',0), array('',0));
    $i=0;
    while ($row = mysql_fetch_array($result)){
        $bw[$i][0] = $row['domein'];
        $bw[$i][1] = round((($row['size'] /1024)/1024),1);

        $i++;
    }

    return $bw;
}

function func_bw_volume_domain_all_periode($Start, $End){
	// Connect to server and select databse.
    global $host, $username, $password, $db_name;

	mysql_connect("$host", "$username", "$password")or die("cannot connect");
	mysql_select_db("$db_name")or die("cannot select DB");

	$sql="SELECT domein, sum(size) as size, (SELECT count(DISTINCT client) FROM logbook l WHERE domein = logbook.domein and Timestamp >= '$Start' and Timestamp <= '$End') as aantcli FROM `logbook` where Timestamp >= '$Start' and Timestamp <= '$End' GROUP BY client";
    $result=mysql_query($sql);


    return $result;
}

function func_bw_volume_domain_all_periode_detail($Start, $End, $Domein){
	// Connect to server and select databse.
    global $host, $username, $password, $db_name;

	mysql_connect("$host", "$username", "$password")or die("cannot connect");
	mysql_select_db("$db_name")or die("cannot select DB");

	$sql="SELECT client, sum(size) as size FROM `logbook` where domein = '$Domein' and Timestamp >= '$Start' and Timestamp <= '$End' GROUP BY client";
    $result=mysql_query($sql);


    return $result;
}

function func_bw_volume_domain_all_periode_detail2($Start, $End, $Domein){
	// Connect to server and select databse.
    global $host, $username, $password, $db_name;

	mysql_connect("$host", "$username", "$password")or die("cannot connect");
	mysql_select_db("$db_name")or die("cannot select DB");

	$sql="SELECT ident, sum(size) as size FROM `logbook` where domein = '$Domein' and Timestamp >= '$Start' and Timestamp <= '$End' GROUP BY ident";
    $result=mysql_query($sql);


    return $result;
}
?>